

 
	
-- ***********************************************************************************************
-- GETUPDATECONFLICT Stored Procedures for the list of tables mentioned in the Initialize file
--------------------------------------------------------------------------------------------------

--TABLE NAME: Customer    STORED PROCEDURE NAME: Sales.sync_sp_Customer_GetUpdateConflict

use [SyncSamplesDb_ChangeTracking_Custom]

if object_id(N'Sales.sync_sp_Customer_GetUpdateConflict', 'P') is not null
	drop procedure Sales.sync_sp_Customer_GetUpdateConflict
GO

	create procedure Sales.sync_sp_Customer_GetUpdateConflict(
        @CustomerId uniqueidentifier       
        )
as
	SELECT		E.CustomerId
				, E.CustomerName
				, E.SalesPerson
				, E.CustomerType
				, CT.SYS_CHANGE_CONTEXT
				, CT.SYS_CHANGE_VERSION 
	FROM		[SyncSamplesDb_ChangeTracking_Custom].[Sales].[Customer] AS E
	JOIN		CHANGETABLE(VERSION [SyncSamplesDb_ChangeTracking_Custom].[Sales].[Customer], ([CustomerId]), (@CustomerId)) AS CT  
				ON E.CustomerId = CT.CustomerId

GO

-------------------------------------------END------------------------------------------------------------------




	
-- ***********************************************************************************************
-- GETUPDATECONFLICT Stored Procedures for the list of tables mentioned in the Initialize file
--------------------------------------------------------------------------------------------------

--TABLE NAME: CustomerContact    STORED PROCEDURE NAME: Sales.sync_sp_CustomerContact_GetUpdateConflict

use [SyncSamplesDb_ChangeTracking_Custom]

if object_id(N'Sales.sync_sp_CustomerContact_GetUpdateConflict', 'P') is not null
	drop procedure Sales.sync_sp_CustomerContact_GetUpdateConflict
GO

	create procedure Sales.sync_sp_CustomerContact_GetUpdateConflict(
        @CustomerId uniqueidentifier
		,@PhoneType nvarchar       
        )
as
	SELECT		E.CustomerId
				, E.PhoneNumber
				, E.PhoneType
				, CT.SYS_CHANGE_CONTEXT
				, CT.SYS_CHANGE_VERSION 
	FROM		[SyncSamplesDb_ChangeTracking_Custom].[Sales].[CustomerContact] AS E
	JOIN		CHANGETABLE(VERSION [SyncSamplesDb_ChangeTracking_Custom].[Sales].[CustomerContact], ([CustomerId], [PhoneType]), (@CustomerId, @PhoneType)) AS CT  
				ON E.CustomerId = CT.CustomerId
				AND E.PhoneType = CT.PhoneType

GO

-------------------------------------------END------------------------------------------------------------------




	
-- ***********************************************************************************************
-- GETUPDATECONFLICT Stored Procedures for the list of tables mentioned in the Initialize file
--------------------------------------------------------------------------------------------------

--TABLE NAME: OrderDetail    STORED PROCEDURE NAME: Sales.sync_sp_OrderDetail_GetUpdateConflict

use [SyncSamplesDb_ChangeTracking_Custom]

if object_id(N'Sales.sync_sp_OrderDetail_GetUpdateConflict', 'P') is not null
	drop procedure Sales.sync_sp_OrderDetail_GetUpdateConflict
GO

	create procedure Sales.sync_sp_OrderDetail_GetUpdateConflict(
        @OrderDetailId int
		,@OrderId uniqueidentifier       
        )
as
	SELECT		E.OrderDetailId
				, E.OrderId
				, E.Product
				, E.Quantity
				, CT.SYS_CHANGE_CONTEXT
				, CT.SYS_CHANGE_VERSION 
	FROM		[SyncSamplesDb_ChangeTracking_Custom].[Sales].[OrderDetail] AS E
	JOIN		CHANGETABLE(VERSION [SyncSamplesDb_ChangeTracking_Custom].[Sales].[OrderDetail], ([OrderDetailId], [OrderId]), (@OrderDetailId, @OrderId)) AS CT  
				ON E.OrderDetailId = CT.OrderDetailId
				AND E.OrderId = CT.OrderId

GO

-------------------------------------------END------------------------------------------------------------------




	
-- ***********************************************************************************************
-- GETUPDATECONFLICT Stored Procedures for the list of tables mentioned in the Initialize file
--------------------------------------------------------------------------------------------------

--TABLE NAME: OrderHeader    STORED PROCEDURE NAME: Sales.sync_sp_OrderHeader_GetUpdateConflict

use [SyncSamplesDb_ChangeTracking_Custom]

if object_id(N'Sales.sync_sp_OrderHeader_GetUpdateConflict', 'P') is not null
	drop procedure Sales.sync_sp_OrderHeader_GetUpdateConflict
GO

	create procedure Sales.sync_sp_OrderHeader_GetUpdateConflict(
        @OrderId uniqueidentifier       
        )
as
	SELECT		E.OrderId
				, E.CustomerId
				, E.OrderDate
				, E.OrderStatus
				, CT.SYS_CHANGE_CONTEXT
				, CT.SYS_CHANGE_VERSION 
	FROM		[SyncSamplesDb_ChangeTracking_Custom].[Sales].[OrderHeader] AS E
	JOIN		CHANGETABLE(VERSION [SyncSamplesDb_ChangeTracking_Custom].[Sales].[OrderHeader], ([OrderId]), (@OrderId)) AS CT  
				ON E.OrderId = CT.OrderId

GO

-------------------------------------------END------------------------------------------------------------------




	
-- ***********************************************************************************************
-- GETUPDATECONFLICT Stored Procedures for the list of tables mentioned in the Initialize file
--------------------------------------------------------------------------------------------------

--TABLE NAME: Vendor    STORED PROCEDURE NAME: Sales.sync_sp_Vendor_GetUpdateConflict

use [SyncSamplesDb_ChangeTracking_Custom]

if object_id(N'Sales.sync_sp_Vendor_GetUpdateConflict', 'P') is not null
	drop procedure Sales.sync_sp_Vendor_GetUpdateConflict
GO

	create procedure Sales.sync_sp_Vendor_GetUpdateConflict(
        @VendorId uniqueidentifier       
        )
as
	SELECT		E.VendorId
				, E.VendorName
				, E.CreditRating
				, E.PreferredVendor
				, CT.SYS_CHANGE_CONTEXT
				, CT.SYS_CHANGE_VERSION 
	FROM		[SyncSamplesDb_ChangeTracking_Custom].[Sales].[Vendor] AS E
	JOIN		CHANGETABLE(VERSION [SyncSamplesDb_ChangeTracking_Custom].[Sales].[Vendor], ([VendorId]), (@VendorId)) AS CT  
				ON E.VendorId = CT.VendorId

GO

-------------------------------------------END------------------------------------------------------------------






